package org.dark.fund.configuration;

import org.dark.fund.filter.HttpLogFilter;
import org.dark.fund.filter.HttpTokenFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

@Configuration
public class FilterConfig {

    HttpLogFilter getHttpLogFilter() {
        return new HttpLogFilter();
    }

    HttpTokenFilter getTokenFilter() {
        return new HttpTokenFilter();
    }


    /**
     * 注册LOG Filter
     * @return
     */
    @Bean
    public FilterRegistrationBean httpLogFilter(){
        FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(getHttpLogFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setOrder(100);
        return filterRegistrationBean;
    }

    /**
     * 注册 token Bean
     * @return
     */
    @Bean
    public FilterRegistrationBean httpTokenFilter(){
        FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(getTokenFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setOrder(200);
        return filterRegistrationBean;
    }


}
